package com.woniuxy.controller;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.woniuxy.entity.User;
import com.woniuxy.service.UserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/user2")
//@CrossOrigin
public class User2Controller {
    @Resource
    private UserService userService;
    @GetMapping
    public List<User> users(){
        List<User> users = userService.queryAll();
        return users;
    }
    @PostMapping
    public Integer addUser(@RequestBody User user){

        Integer add = userService.add(user);
        return add;
    }
    @GetMapping("{id}")
    public User user(@PathVariable Integer id){
        User user = userService.queryById(id);
        return user;
    }
    @PutMapping
    public Integer update(@RequestBody User user){
        Integer update = userService.updateByIdSelective(user);
        return update;
    }
    @DeleteMapping("{id}")
    public Integer delete(@PathVariable Integer id){
        Integer delete = userService.delete(id);
        return delete;
    }
}
